package cn.edu.hhu.servlet.admin;

import cn.edu.hhu.Bean.Student;
import cn.edu.hhu.Bean.Teacher;
import cn.edu.hhu.service.AdminService;
import cn.edu.hhu.service.Impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @anthor: lddd
 * @date: 2020/5/17 - 15:18
 * @description:
 **/
@WebServlet("/admin/queryAllTeacherServlet")
public class QueryAllTeacherServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1获取id
        String tid = request.getParameter("tid");
        //2调用service删除
        AdminService adminService = new AdminServiceImpl();
        if (!adminService.deleteTeacher(tid)) {
            request.setAttribute("msg", "删除失败！");
        }
        System.out.println("要删除的tid" + tid);
        //3跳转到查询所有的servlet
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1查询所有学生
        AdminService adminService = new AdminServiceImpl();
        List<Teacher> list = adminService.queryAllTeacher();
        //2存在request中
        request.setAttribute("allTeachers", list);
        //3转发
        request.getRequestDispatcher("/admin/teacher_management.jsp").forward(request, response);
    }
}
